package com.novax.ex.activity.provider.service;

import com.novax.ex.activity.infrastructure.entity.MallBanner;
import com.novax.ex.activity.infrastructure.mapper.MallBannerMapper;
import com.novax.ex.common.base.BaseEntity;
import com.novax.ex.common.base.BaseMapper;
import com.novax.ex.common.base.BaseService;
import com.novax.ex.common.enums.LanguageType;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import jakarta.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description: 一元购-轮播图
 *
 * @author Deucalion@novax.email
 * @date 2023/3/16 10:13
 */
@Service
public class MallBannerService extends BaseService {
    @Resource
    private MallBannerMapper mallBannerMapper;
    @Override
    protected BaseMapper getBaseMapper() {
        return mallBannerMapper;
    }

    /** 根据语言查询数据 */
    public MallBanner findByLanguage(String language) {
        return mallBannerMapper.selectByLanguage(language);
    }

    /** 数据软删除 */
    public boolean removeById(Long id, Long adminId) {
        return mallBannerMapper.removeById(id,adminId) > 0;
    }

    /**
     * @description: 查询前台列表，按照语言返回列表
     * @author: Wade
     * @date: 3/16/23 1:52 PM
     * @param: [language]
     * @return: java.util.List<com.novax.ex.activity.infrastructure.entity.MallBanner>
     **/
    public List<MallBanner> queryList(String language) {
        Map<String,Object> map = new HashMap<>();
        map.put("language",language);
        map.put("isShow",1);
        map.put("isDelete",0);
        List<MallBanner> baseEntities = mallBannerMapper.selectList(map);
        if(CollectionUtils.isEmpty(baseEntities)){
            map.put("language", LanguageType.en.getType());
            baseEntities = mallBannerMapper.selectList(map);
        }
        return baseEntities;
    }
}
